package sbe.sonar.client.database;

import java.io.Serializable;

import javax.persistence.*;

import java.util.List;


/**
 * The persistent class for the Application database table.
 * 
 */
@Entity
@Table(name="Application", schema="SVNApplications")
@NamedQuery(name="Application.findAll", query="SELECT a FROM Application a")
public class Application implements Serializable {
	private static final long serialVersionUID = 1L;
	private String idApplication;
	private String regularExpression;
	private String sonarKey;
	private List<ApplicationsByRepository> applicationsByRepositories;
	private List<ModulesByApplication> modulesByApplications;
	private List<Repository> repositories;
	private List<Module> modules;

	public Application() {
	}


	@Id
	public String getIdApplication() {
		return this.idApplication;
	}

	public void setIdApplication(String idApplication) {
		this.idApplication = idApplication;
	}


	public String getRegularExpression() {
		return this.regularExpression;
	}

	public void setRegularExpression(String regularExpression) {
		this.regularExpression = regularExpression;
	}


	public String getSonarKey() {
		return this.sonarKey;
	}

	public void setSonarKey(String sonarKey) {
		this.sonarKey = sonarKey;
	}


	//bi-directional many-to-one association to ApplicationsByRepository
	@OneToMany(mappedBy="application", fetch=FetchType.EAGER)
	public List<ApplicationsByRepository> getApplicationsByRepositories() {
		return this.applicationsByRepositories;
	}

	public void setApplicationsByRepositories(List<ApplicationsByRepository> applicationsByRepositories) {
		this.applicationsByRepositories = applicationsByRepositories;
	}

	public ApplicationsByRepository addApplicationsByRepository(ApplicationsByRepository applicationsByRepository) {
		getApplicationsByRepositories().add(applicationsByRepository);
		applicationsByRepository.setApplication(this);

		return applicationsByRepository;
	}

	public ApplicationsByRepository removeApplicationsByRepository(ApplicationsByRepository applicationsByRepository) {
		getApplicationsByRepositories().remove(applicationsByRepository);
		applicationsByRepository.setApplication(null);

		return applicationsByRepository;
	}


	//bi-directional many-to-one association to ModulesByApplication
	@OneToMany(mappedBy="application", fetch=FetchType.EAGER)
	public List<ModulesByApplication> getModulesByApplications() {
		return this.modulesByApplications;
	}

	public void setModulesByApplications(List<ModulesByApplication> modulesByApplications) {
		this.modulesByApplications = modulesByApplications;
	}

	public ModulesByApplication addModulesByApplication(ModulesByApplication modulesByApplication) {
		getModulesByApplications().add(modulesByApplication);
		modulesByApplication.setApplication(this);

		return modulesByApplication;
	}

	public ModulesByApplication removeModulesByApplication(ModulesByApplication modulesByApplication) {
		getModulesByApplications().remove(modulesByApplication);
		modulesByApplication.setApplication(null);

		return modulesByApplication;
	}


	//bi-directional many-to-many association to Repository
	@ManyToMany(mappedBy="applications", fetch=FetchType.EAGER)
	public List<Repository> getRepositories() {
		return this.repositories;
	}

	public void setRepositories(List<Repository> repositories) {
		this.repositories = repositories;
	}


	//bi-directional many-to-many association to Module
	@ManyToMany(fetch=FetchType.EAGER, cascade={CascadeType.PERSIST, CascadeType.REMOVE})
	@JoinTable(
		name="ModulesByApplication"
		, joinColumns={
			@JoinColumn(name="idApplication")
			}
		, inverseJoinColumns={
			@JoinColumn(name="idModule")
			}
		)
	public List<Module> getModules() {
		return this.modules;
	}

	public void setModules(List<Module> modules) {
		this.modules = modules;
	}

}